/*
 * Move.java
 *
 * Created on 15 December, 2008, 12:56 AM
 *@author Pranay
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package vrp;

/**
 * Class representing a move (in the algorithm meaning).
 * A move means moving a customer from a round to another so it is linked to another car
 * @author Pranay
 */
public class Move {
    
	/**
	 * Customer we move from a round to another
	 */
    private Customer customer;

    /**
     * Initial round in which the customer was
     */
    private Vehicle initCar;

    /**
     * Final round in which we have moved the customer
     */
    private Vehicle finalCar;
    
    /**
     * Position (index) of the customer in the new round
     */
    private int finalPos;
    
    private double cost, length;

    
    /** Creates a new instance of Move */
    public Move() {
    }
    
    public Move(double val) {
        cost=val;
    }
    
    void setLength(double l) {
        length=l;
    }
    
    double getLength() {
        return length;
    }
    
    void updateLength(double updater) {
        length+=updater;
    }

    void setCustomer(Customer customer) {
        this.customer=customer;
    }

    void setInitCar(Vehicle initCar) {
        this.initCar=initCar;
    }

    void setFinalCar(Vehicle finalCar) {
        this.finalCar=finalCar;
    }

    void setNewCost(double d) {
        cost=d;
    }

    void setFinalPosition(int d) {
        finalPos=d;
    }

    double getCost() {
        return cost;
    }

    Customer getCustomer() {
        return customer;
    }

    Vehicle getInitCar() {
        return initCar;
    }

    int getFinalPosition() {
        return finalPos;
    }

    Vehicle getFinalCar() {
        return finalCar;
    }
    
    /**
     * Updates a move with the given values if the new cost is better than the actual
     * @param incCurrent Cost of the given move
     * @param index New index of the customer in the given round
     * @param car New car (round) of the customer
     * @param distCh Distance added in the new round
     */
    void updateMove(double incCurrent, int index, Vehicle car, double distCh) {
        if (cost>incCurrent) {
            finalPos=index;
            cost=incCurrent;
            finalCar=car;
            length=distCh;
        }
    }

    void updateMove(Move auxMove) {
        if (cost>auxMove.getCost()) {
            customer=auxMove.getCustomer();
            initCar=auxMove.getInitCar();
            finalCar=auxMove.getFinalCar();
            finalPos=auxMove.getFinalPosition();
            cost=auxMove.getCost();
            length=auxMove.getLength();
        }
    }

    void inverseMove() {
        Vehicle auxCar=initCar;
        //int auxPos=finalPos;
        initCar=finalCar;
        finalCar=auxCar;
        finalPos=customer.getPosition();
        //customer.setPosition(auxPos);
        length=-length;
    }
    
}
